package cn.inst.attend.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.inst.attend.domain.Attend;
import cn.inst.attend.service.AttendService;
import cn.inst.attend.vo.PageCondition;
import cn.inst.common.page.PageQueryBean;
import cn.inst.user.domain.User;
/**
 * 控制打卡的类
 * @author yeyongjian
 *
 */

@Controller
@RequestMapping("attend")
public class AttendController {
	@Resource(name="attendServiceImp")
	private AttendService attendService;
	/**
	 * 不知有何用
	 * @return
	 */
	@RequestMapping("/attend")
	@RequiresPermissions("attend:attendlist")
	public String toAttend(){
		
		return "attend";
	}
	
	/**
	 * 打卡的接口
	 * @return
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping("/sign")
	public String signAttend(@RequestBody Attend attend) throws Exception{
		System.out.println("进入打卡程序");
		attendService.signAttend(attend);
		return "home";
		
	}
	
	/**
	 * 	
	 * 
	 * @param pCondition
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/page")
	public PageQueryBean getPage(PageCondition pCondition,HttpSession session){
		System.out.println("进入分页查询");
		User user = (User) session.getAttribute("userinfo");
		String[] rangDate = pCondition.getRangeDate().split("/");
		//数据封装
		pCondition.setBeginDate(rangDate[0]);
		pCondition.setEndDate(rangDate[1]);
		pCondition.setUserId(user.getId());
		return attendService.getPage(pCondition);
		
	}
}
